//
//  PlayerControlView.swift
//  UILibrarysKit
//
//  Created by TSYH on 2024/5/13.
//

import UIKit

@objc public protocol BMPlayerControlViewDelegate {
    /**
     call when control view choose a definition
     
     - parameter controlView: control view
     - parameter index:       index of definition
     */
    func controlView(controlView: UIView, didChooseDefinition index: Int)
    
    /**
     call when control view pressed an button
     
     - parameter controlView: control view
     - parameter button:      button type
     */
    func controlView(controlView: UIView, didPressButton button: UIButton)
    
    func controlView(controlView: UIView, action: PlayerControlAction)
    
    /**
     call when slider action trigged
     
     - parameter controlView: control view
     - parameter slider:      progress slider
     - parameter event:       action
     */
    func controlView(controlView: UIView, slider: UISlider, onSliderEvent event: UIControl.Event)
    
    /**
     call when needs to change playback rate
     
     - parameter controlView: control view
     - parameter rate:        playback rate
     */
    @objc optional func controlView(controlView: UIView, didChangeVideoPlaybackRate rate: Float)
}

public protocol PlayerControlView where Self: UIView {
    /// 事件响应，用weak，避免循环引用
    var delegate: BMPlayerControlViewDelegate? { get set }
    
    /// 所属播放器，用weak，避免循环引用
    var player: BMPlayer? { get set }
    
    /// 是否支持双击控制播放
    var enablePlayControlGestures: Bool { get }
    
    /// 缓存进度变化
    func player(_ player: BMPlayer, didLoad duration: TimeInterval, total: TimeInterval)
    
    /// 播放进度变化
    func player(_ player: BMPlayer, timeDidChange current: TimeInterval, total: TimeInterval)
    
    /// 快进 || 快退
    func player(_ player: BMPlayer, seekTo target: TimeInterval, total: TimeInterval, isAdd: Bool)
    
    /// 控制面板显隐
    func player(_ player: BMPlayer, toggleShow animated: Bool)
    
    func updateUI(_ isForFullScreen: Bool)
    func showLoader()
    
    func playStateDidChange(isPlaying: Bool)
    func playerStateDidChange(state: BMPlayerState)
    
    func hideSeekToView()
    func prepareToDealloc()
    func hidePlayToTheEndView()
    func hideCoverImageView()
    func showCover(url: URL?)
    func hideLoader()
    func prepareUI(for resource: BMPlayerResource, selectedIndex index: Int)
}
